import Platform
class Something(Platform.Platform):
	def __init__(self,x=0,y=0,mass=50,f_right=True):
		self.x=x
		self.y=y
		self.prev_x=x#self.x
		self.prev_y=y#self.y
		self.x_bound=None
		self.y_bound=None
		self.ownMass=mass
		self.facingRight=f_right
		self.x_cling=False
		self.hangsFromButtom=False
		self.dead=False
		self.Fx=0
		self.Fy=0
		self.dx=0
		self.dy=0
		self.fraction=0
	def getAgility(self):
		return 0
	def getStrength(self):
		return 0
	def getToughness(self):
		return 0
	def getImpulse(self):
		return (self.getMass()*((self.x-self.prev_x)**2+(self.y-self.prev_y)**2)**0.5)/(1.0/24)
	def rebound(self,rx,ry):
		p=self.getImpulse()
		self.reposition(rx,ry)
		self.threshold(p)
		return p
	def reposition(self,rx,ry):
		#self.prev_x=self.x
		#self.prev_y=self.y
		self.x=rx
		self.y=ry
		#self.coordDump()
	def coordDump(self):
		self.prev_x=self.x
		self.prev_y=self.y
	def intermediate_x(self,y):#,extra):
		if self.y==self.prev_y or not (self.y<=y<=self.prev_y or self.y>=y>=self.prev_y):
			#if (self.y<=y<=self.prev_y or self.y>=y>=self.prev_y):
			#	return extra
			return self.x
		return (self.x-self.prev_x)*(y-self.prev_y)/(self.y-self.prev_y)+self.prev_x
	def intermediate_y(self,x):
		if self.x==self.prev_x or not (self.x<=x<=self.prev_x or self.x>=x>=self.prev_x):
			return self.y
		return (self.y-self.prev_y)*(x-self.prev_x)/(self.x-self.prev_x)+self.prev_y
	def bounceY(self,cx,cy):
		self.y=cy+cy-self.y
		self.prev_y=cy+cy-self.prev_y
	def bounceX(self,cx,cy):
		self.x=cx+cx-self.x
		self.prev_x=cx+cx-self.prev_x
	def threshold(self,p):
		print "ai-iaaa!",p,"!!"
		#thresh1=self.getMass()*(3.0*2*176*980)**0.5
		thresh1=self.getMass()*(3.0*2*self.getHeight()*980)**0.5
		print thresh1
		if thresh1<p:
			damage=0.002*(p-thresh1)
			self.physicalDamageTaken(damage)
			#self.die()
	def freeFall(self,Fx=0,Fy=0):
		#print "this char is falling.. up or down.."
		m=self.getMass()
		dt=1.0/24
		k=0
		dy=self.prev_y+(2.0*(self.y-self.prev_y)*m+(Fy-980*m)*dt*dt)/(m+0.5*k*dt)-self.y
		dx=self.prev_x+(2.0*(self.x-self.prev_x)*m+(Fx)*dt*dt)/(m+0.5*k*dt)-self.x
		return dx,dy
	def bumpY(self,cx,cy):
		#self.coordDump()
		self.reposition(cx,cy)
		#dx,dy=self.freeFall()
		x=self.x+(self.x-self.prev_x)*1.0/24
		y=self.y+(self.y-self.prev_y)*1.0/24
		self.reposition(x,y)
		self.bounceY(cx,cy)
	def bumpX(self,cx,cy):
		self.reposition(cx,cy)
		#dx,dy=self.freeFall()
		x=self.x+(self.x-self.prev_x)*1.0/24
		y=self.y+(self.y-self.prev_y)*1.0/24
		self.reposition(x,y)
		self.bounceX(cx,cy)
	def bumping(self):
		return False
	def thereIsNothingElse(self,here,it):
		return False
	def add_dy(self,value):
		self.dy=self.dy+value
	def add_dx(self,value):
		self.dx=self.dx+value
	def add_FX(self,FX):
		self.Fx=self.Fx+FX
	def add_FY(self,FY):
		self.Fy=self.Fy+FY
	def process(self):
		#print "my cur state is",self.currentState
		#print self.prev_x,self.x,repr(self.x+0.5*self.getWidth())
		self.solveDecisions()
		self.decisionQueue=[]
		self.updateCoords()
		self.postcondition()
		self.Fx=0
		self.Fy=0
		self.dx=0
		self.dy=0
		if self.y_bound:
			self.y_bound.hasFallenOff_y(self)
		if self.x_bound:
			self.x_bound.hasFallenOff_x(self)
		if self.stunned>0:
			self.stunned=self.stunned-1
	def mFreedom(self):
		return not (bool(self.x_bound) and bool(self.x_bound))
	def leftSide(self):
		return self.x-0.5*self.getWidth()
	def rightSide(self):
		return self.x+0.5*self.getWidth()
	def upperSide(self):
		return self.y+self.getHeight()
	def lowerSide(self):
		return self.y
	def hit_by_object(self,objecto):
		if objecto.fraction!=self.fraction and self.cur_room is objecto.cur_room:
			#self.die()
			objecto.damageDealt(self)
			#self.physicalDamageTaken(a)
			objecto.hitResult()
	def reaction_up(self,objecto):
		self.hit_by_object(objecto)
	def reaction_left(self,objecto):
		self.hit_by_object(objecto)
	def reaction_right(self,objecto):
		self.hit_by_object(objecto)
	def reaction_down(self,objecto):
		self.hit_by_object(objecto)
	def totalUnbound(self):
		if self.y_bound:
			self.y_bound.unbound(self)
		if self.x_bound:
			self.x_bound.unbound(self)
		